package com.atguigu.springFirst;

import org.junit.jupiter.api.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/*
@description:
@ClassName TestUser
@author chen
@create 2023-08-03 22:42
@Version 1.0
*/
public class TestUser {
    @Test
    public void testUserObject() {
        /**
         * 使用ClassPathXmlApplicationContext加载spring的xml配置文件,读取bean中的user对象,调用了User类的无参构造器
         */
        // 1.加载spring的配置文件
        ApplicationContext context
                     = new ClassPathXmlApplicationContext("spring.xml");
        // 2.获取创建的对象
        User user = (User) context.getBean("user");
        System.out.println("1:---->>>日志记录");
        // 3.调用方法
        user.add();
    }

    @Test
    public void testUserObject1() throws Exception {
        // 使用反射创建对象
        Class clazz = Class.forName("com.atguigu.springFirst.User");
        User user = (User) clazz.getDeclaredConstructor().newInstance();
        System.out.println(user);
    }
}
